package com.atm.atmsys.Service.Imp;

import com.atm.atmsys.Mapper.AtmMapper.AtmMapper;
import com.atm.atmsys.Service.AtmService;
import com.atm.atmsys.dto.ATMPageQueryDTO;
import com.atm.atmsys.dto.AtmDTO;
import com.atm.atmsys.entity.AdminInfo;
import com.atm.atmsys.entity.AtmInfo;
import com.atm.atmsys.entity.PageResult;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

import static com.atm.atmsys.constant.StatusConstant.DefaultStatus;

@Service
public class AtmServiceImp implements AtmService {


    @Autowired
    private AtmMapper atmMapper;

    //添加ATM机
    @Override
    public void addAtm(AtmInfo atmInfo) {
        atmInfo.setAtmStatus(DefaultStatus);
        atmMapper.addAtm(atmInfo);
    }

    //根据Id删除ATM机
    @Override
    public void deleteAtm(Integer id) {
        atmMapper.deleteAtm(id);
    }



    //根据ID查询ATM机
    @Override
    public AtmInfo getAtmById(Integer id) {
        return atmMapper.getAtmById(id);
    }


    //根据ID修改ATM机状态
    @Override
    public void updateAtm(AtmDTO atmDTO) {
        AtmInfo atmInfo = new AtmInfo();
        BeanUtils.copyProperties(atmDTO, atmInfo);
        System.out.println(atmInfo);
        atmMapper.updateAtm(atmInfo);
    }


    //查询所有ATM机
    @Override
    public PageResult getAllAtm(ATMPageQueryDTO atmPageQueryDTO) {
        PageHelper.startPage(atmPageQueryDTO.getPage(), atmPageQueryDTO.getPageSize());
        Page<AtmInfo> page =atmMapper.pageQuery(atmPageQueryDTO);
        long total = page.getTotal();
        List<AtmInfo> result = page.getResult();
        return new PageResult(total,result);
    }

    //查询所有ATM机不分页
    @Override
    public List<AtmInfo> getAtm() {
        List<AtmInfo> atmInfos = atmMapper.getAtm();
        return atmInfos;
    }


}
